package com.sdy.dao.redis;

import com.alibaba.fastjson.JSONObject;
import com.sdy.po.Parm;
import com.sdy.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
@SuppressWarnings("all")
public class CompanyDao {

    @Autowired
    RedisUtil redisUtil;

    public Integer getCompanyId(String code){
        return (Integer) redisUtil.get("companyCode:" + code);
    }

    public Boolean isKeyExist(String key){
        return redisUtil.hasKey(key);
    }

    public String getParmState(Integer companyId,String parmName){
        return redisUtil.get("parmState:"+companyId+":"+parmName).toString();
    }

    /**
     * 获得这个这个参数的运行状况
     * @param companyId
     * @param parm
     * @param state
     * @return
     */
    public Boolean setParmState(Integer companyId, Parm parm, String state){
        return redisUtil.set("parmState:"+companyId+":"+parm.geteName(),state);
    }

    //存放公司识别码
    public Boolean setConpanyCode(Integer companyId,String code,Integer time){
        try {
            redisUtil.set("companyCode:" + companyId ,code,time);
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }

    //用于创建websocket连接的键值对
    public Boolean setConnectCode(Integer companyId,String code, Integer time){
        try {
            redisUtil.set("companyCode:" + code ,companyId,time);
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }
}
